package com.atguigu.gmall.product.service.impl;

import com.alibaba.fastjson.JSON;
import com.atguigu.gmall.product.mapper.SpuSaleAttrMapper;
import com.atguigu.gmall.product.pojo.SpuSaleAttr;
import com.atguigu.gmall.product.service.SpuSaleAttrService;
import com.atguigu.gmall.product.vo.SpuSaleAttrVo;
import com.atguigu.gmall.product.vo.ValueSkuJsonVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author h8467
* @description 针对表【spu_sale_attr(spu销售属性)】的数据库操作Service实现
* @createDate 2022-11-29 16:02:29
*/
@Service
public class SpuSaleAttrServiceImpl extends ServiceImpl<SpuSaleAttrMapper, SpuSaleAttr>
    implements SpuSaleAttrService{


    @Override
    public   List<SpuSaleAttrVo>  getSpuSaleAttrList(Long spuId) {
        List<SpuSaleAttrVo> list = baseMapper.getSpuSaleAttrList(spuId);
        return list;
    }

    @Override
    public List<SpuSaleAttr> getSpuSaleAttr(Long spuId,Long skuId) {
        List<SpuSaleAttr> list = baseMapper.getSpuSaleAttr(spuId ,skuId);
        return list;
    }

    @Override
    public String getValuesSpuJson(Long spuId) {
        List<ValueSkuJsonVo> list = baseMapper.getValuesSpuJson(spuId);
        Map<String, Long> collect = list.stream().collect(Collectors.toMap(ValueSkuJsonVo::getValueJson, ValueSkuJsonVo::getSkuId));
        return JSON.toJSONString(collect);
    }
}




